﻿using System.Collections;

namespace Bzstd.Utility.Assertion;

/// <summary>
/// Dictionary断言类
/// </summary>
public static partial class Assert
{
	/// <summary>
	/// Dictionary无空Value断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="T"></typeparam>
	/// <returns></returns>
	public static T NoNullValues<T>(T dictionary, string message) where T : IDictionary
	{
		NoNullElements(dictionary.Values, message);
		return dictionary;
	}

	/// <summary>
	/// Dictionary非空且无空Value断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="T"></typeparam>
	/// <returns></returns>
	public static T NotEmptyAndNoNullValues<T>(T dictionary, string message) where T : IDictionary
	{
		NotEmpty(dictionary, message);
		NoNullValues(dictionary, message);
		return dictionary;
	}

	/// <summary>
	/// Dictionary无空Key断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="T"></typeparam>
	/// <returns></returns>
	public static T NoNullKeys<T>(T dictionary, string message) where T : IDictionary
	{
		NoNullElements(dictionary.Keys, message);
		return dictionary;
	}

	/// <summary>
	/// Dictionary非空且无空Key断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="T"></typeparam>
	/// <returns></returns>
	public static T NotEmptyAndNoNullKeys<T>(T dictionary, string message) where T : IDictionary
	{
		NotEmpty(dictionary, message);
		NoNullKeys(dictionary, message);
		return dictionary;
	}

	/// <summary>
	/// Dictionary无空Value断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <returns></returns>
	public static IDictionary<K, string> NoEmptyValues<K>(IDictionary<K, string> dictionary, string message)
	{
		if (null != dictionary)
		{
			NoEmptyElements(dictionary.Values, message);
		}
		return dictionary;
	}

	/// <summary>
	/// Dictionary非空且无空Value断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <returns></returns>
	public static IDictionary<K, string> NotEmptyAndNoEmptyValues<K>(IDictionary<K, string> dictionary, string message)
	{
		NotEmpty(dictionary, message);
		NoEmptyValues(dictionary, message);
		return dictionary;
	}

	/// <summary>
	/// Dictionary无空Key断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static IDictionary<string, V> NoEmptyKeys<V>(IDictionary<string, V> dictionary, string message)
	{
		if (null != dictionary)
		{
			NoEmptyElements(dictionary.Keys, message);
		}
		return dictionary;
	}

	/// <summary>
	/// Dictionary非空且无空Key断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static IDictionary<string, V> NotEmptyAndNoEmptyKeys<V>(IDictionary<string, V> dictionary, string message)
	{
		NotEmpty(dictionary, message);
		NoEmptyKeys(dictionary, message);
		return dictionary;
	}

	/// <summary>
	/// Dictionary无空Value断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <returns></returns>
	public static IDictionary<K, string> NoBlankValues<K>(IDictionary<K, string> dictionary, string message)
	{
		if (null != dictionary)
		{
			NoBlankElements(dictionary.Values, message);
		}
		return dictionary;
	}

	/// <summary>
	/// Dictionary非空且无空Value断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <returns></returns>
	public static IDictionary<K, string> NotEmptyAndNoBlankValues<K>(IDictionary<K, string> dictionary, string message)
	{
		NotEmpty(dictionary, message);
		NoBlankValues(dictionary, message);
		return dictionary;
	}

	/// <summary>
	/// Dictionary无空Key断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static IDictionary<string, V> NoBlankKeys<V>(IDictionary<string, V> dictionary, string message)
	{
		if (null != dictionary)
		{
			NoBlankElements(dictionary.Keys, message);
		}
		return dictionary;
	}

	/// <summary>
	/// Dictionary非空且无空Key断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static IDictionary<string, V> NotEmptyAndNoBlankKeys<V>(IDictionary<string, V> dictionary, string message)
	{
		NotEmpty(dictionary, message);
		NoBlankKeys(dictionary, message);
		return dictionary;
	}

	/// <summary>
	/// Dictionary唯一断言获取Value
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static V SingleValue<K, V>(IDictionary<K, V> dictionary, string message)
	{
		return SingleElement(dictionary, message).Value;
	}

	/// <summary>
	/// Dictionary唯一断言获取Key
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static K SingleKey<K, V>(IDictionary<K, V> dictionary, string message)
	{
		return SingleElement(dictionary, message).Key;
	}

	/// <summary>
	/// Dictionary唯一且Value非空断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static V SingleNotNullValue<K, V>(IDictionary<K, V> dictionary, string message)
	{
		return NotNull(SingleElement(dictionary, message).Value, message);
	}

	/// <summary>
	/// Dictionary唯一且Key非空断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static K SingleNotNullKey<K, V>(IDictionary<K, V> dictionary, string message)
	{
		return NotNull(SingleElement(dictionary, message).Key, message);
	}

	/// <summary>
	/// Dictionary唯一且Value非空断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static string SingleNotEmptyValue<K, V>(IDictionary<K, V> dictionary, string message)
	{
		return NotEmpty((object) SingleElement(dictionary, message).Value as string, message);
	}

	/// <summary>
	/// Dictionary唯一且Key非空断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static string SingleNotEmptyKey<K, V>(IDictionary<K, V> dictionary, string message)
	{
		return NotEmpty(SingleElement(dictionary, message).Key as string, message);
	}

	/// <summary>
	/// Dictionary唯一且Value非空断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static string SingleNotBlankValue<K, V>(IDictionary<K, V> dictionary, string message)
	{
		return NotBlank(SingleElement(dictionary, message).Value as string, message);
	}

	/// <summary>
	/// Dictionary唯一且Key非空断言
	/// </summary>
	/// <param name="dictionary"></param>
	/// <param name="message"></param>
	/// <typeparam name="K"></typeparam>
	/// <typeparam name="V"></typeparam>
	/// <returns></returns>
	public static string SingleNotBlankKey<K, V>(IDictionary<K, V> dictionary, string message)
	{
		return NotBlank(SingleElement(dictionary, message).Key as string, message);
	}
}
